package com.vcredit.creditcat.manager;


import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.vcredit.creditcat.api.ISMSMessageManager;
import com.vcredit.creditcat.enumtype.MessageTypeEnum;
import com.vcredit.creditcat.model.DefaultSend;
import com.vcredit.creditcat.model.Send;
import com.vcredit.creditcat.service.MessageService;
import com.vcredit.creditcat.service.product.lrh.LrhApplyServiceImpl;
import com.vcredit.creditcat.util.Constants;
import com.vcredit.framework.annotation.Log;
import com.vcredit.framework.util.VelocityUtil;

@Service(protocol = { "protocol1" }, version = "1.0")
public class SMSMessageManager implements ISMSMessageManager {
	@Autowired
	private MessageService messageService;

	
	private static Logger logger = LoggerFactory.getLogger(SMSMessageManager.class);
	
	
	@Override
	public void sendVerificationCode(String mobile, String code, Integer businessType) throws Exception {
		Send send = new DefaultSend(
				UUID.randomUUID().toString().replaceAll("-", ""), VelocityUtil.templateToText("template/SMSTemplate.vm",
						"vcode", code, "time", Constants.SMS_EXPIRE_TIME / 60),
				mobile, MessageTypeEnum.VCODE.getCode());
		messageService.sendVerificationCode(send, mobile, code);
	}
	@Log
	@Override
	public void sendCreditSuccess(String mobile,String productName,String userName) throws Exception {
		String mes=(VelocityUtil.templateToText("template/creditSuccess.vm")).replace("$Product", productName).replace("$UserName", userName);
		logger.info("SendSms:Success#"+mes);
		Send send = new DefaultSend(
				UUID.randomUUID().toString().replaceAll("-", ""), mes,mobile, MessageTypeEnum.SMS.getCode());
		messageService.sendNotice(send, mobile, null);
	}
	@Log
	@Override
	public void sendCreditFail(String mobile,String productName,String userName) throws Exception {
		String mes=(VelocityUtil.templateToText("template/creditFail.vm")).replace("$Product", productName).replace("$UserName", userName);
		logger.info("SendSms:Fail#"+mes);
		Send send = new DefaultSend(
				UUID.randomUUID().toString().replaceAll("-", ""), mes,
				mobile, MessageTypeEnum.SMS.getCode());
		messageService.sendNotice(send, mobile, null);
	}

	
	
}
